package org.jeecg.modules.xxgx.dzsjdl.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.innerApi.common.requestDto.CommonParam;
import org.jeecg.modules.innerApi.common.requestDto.DpdlParam;
import org.jeecg.modules.innerApi.common.responseDto.CreditRtn;
import org.jeecg.modules.innerApi.common.responseDto.FaceImgRtn;
import org.jeecg.modules.innerApi.zhiYunSdApi.responseVo.SdQyfxcxcc116Rtn;
import org.jeecg.modules.innerApi.zhiYunSdApi.service.IZhiyunSdfpService;
import org.jeecg.modules.xxgx.common.service.IXxBase;
import org.jeecg.modules.xxgx.kpzdgl.entity.CsXxKpzd;
import org.jeecg.modules.xxgx.kpzdgl.service.ICsXxKpzdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 电子税务局
 */
@Api(tags = "电子税务局")
@RestController
@RequestMapping("/xxgx/dzswj")
@Slf4j
public class DzsjdlController {
    @Autowired
    private IZhiyunSdfpService zhiyunSdfpService;

    @Autowired
    private ICsXxKpzdService kpzdService;
    @Autowired
    private IXxBase base;
    /**
     * 登录电票平台
     *
     * @param kpzddm
     * @param req
     * @return
     */
    @ApiOperation(value = "登录电票平台", notes = "登录电票平台")
    @GetMapping(value = "/login")
    public Result<String> login(
            @ApiParam(value = "开票终端代码", required = true)
            @RequestParam(name = "kpzddm", required = true) String kpzddm,
            @ApiParam(value = "登录类型", required = false)
            @RequestParam(name = "dllx", required = false) String dllx,
            @ApiParam(value = " 二次登录验证值:短信登录，传短信验证码；二维码登录传二维码id(第一次调用不传，第二次调用传登录)", required = false)
            @RequestParam(name = "verify", required = false) String verify,
            HttpServletRequest req) {
          return base.loginDppt(kpzddm,dllx,verify);
    }

    @ApiOperation(value = "获取是否需要人脸识别", notes = "获取是否需要人脸识别")
    @GetMapping(value = "/getFaceImgState")
    public Result<CreditRtn.CreditRtnData> getFaceImgState(
            @ApiParam(value = "开票终端代码", required = true)
            @RequestParam(name = "kpzddm", required = true) String kpzddm,
            HttpServletRequest req) {
        CommonParam commonParam = kpzdService.getCommonParamByKpzd(kpzddm);
        CsXxKpzd csXxKpzd = commonParam.getKpzd();
        CreditRtn creditRtn = zhiyunSdfpService.getCreditLine(csXxKpzd.getNsrsbh(),commonParam);
        if (creditRtn.getSuccess()) {
            return Result.OK(creditRtn.getData());
        } else {
            return Result.error(creditRtn.getMsg());
        }
    }


    @ApiOperation(value = "获取人脸二维码", notes = "获取人脸二维码")
    @GetMapping(value = "/getFaceImg")
    public Result<FaceImgRtn.FaceImgRtnData> getFaceImg(
            @ApiParam(value = "开票终端代码", required = true)
            @RequestParam(name = "kpzddm", required = true) String kpzddm,
            @ApiParam(value = "类型(值为2获取个人所得税二维码，不传或者其他值都是税局 app 二维码)", required = false)
            @RequestParam(name = "type", required = false) String type,
            HttpServletRequest req) {
        return base.getSmrzEwm(kpzddm,type);
    }

    @ApiOperation(value = "授信额度查询", notes = "授信额度查询")
    @GetMapping(value = "/getCreditLine")
    public Result<CreditRtn.CreditRtnData> getCreditLine(
            @ApiParam(value = "开票终端代码", required = true)
            @RequestParam(name = "kpzddm", required = true) String kpzddm,
            HttpServletRequest req) {
        return base.getCredit(kpzddm);
    }

    /**
     * 企业风险查询
     *
     * @param kpzddm
     * @param req
     * @return
     */
    @ApiOperation(value = "企业风险查询", notes = "企业风险查询")
    @GetMapping(value = "/getCompanyFxcx")
    public Result<SdQyfxcxcc116Rtn> getCompanyFxcx(
            @ApiParam(value = "开票终端代码", required = true)
            @RequestParam(name = "kpzddm", required = true) String kpzddm,
            HttpServletRequest req) {
        CommonParam commonParam = kpzdService.getCommonParamByKpzd(kpzddm);
        CsXxKpzd csXxKpzd = commonParam.getKpzd();
        DpdlParam dpdlParam = new DpdlParam();
        dpdlParam.setNsrsbh(csXxKpzd.getNsrsbh());
        dpdlParam.setUsername(csXxKpzd.getDzswjzh());
        dpdlParam.setPassword(csXxKpzd.getDzswjmm());
        dpdlParam.setKpzd(commonParam.getKpzd());
        dpdlParam.setQyxx(commonParam.getQyxx());
        dpdlParam.setFwqxx(commonParam.getFwqxx());
        SdQyfxcxcc116Rtn commonRtn = zhiyunSdfpService.getCompanyFxcx(dpdlParam);
        if (commonRtn.getSuccess()) {
            return Result.OK(commonRtn);
        } else {
            return Result.error(commonRtn.getMsg());
        }
    }

}
